layui.define([ 'form', 'laydate', 'table' ], function(exports) {
    var form = layui.form;
    var laydate = layui.laydate;
    var table = layui.table;
    var siteFundsTable = null;
    var view ={
        init:function(){
            this.initTable();
            this.initSearchForm();
            this.initToolBar();
            window.dataReload = function(){
                Lib.doSearchForm($("#searchForm"),siteFundsTable)
            }
        },
        initTable:function(){
            siteFundsTable = table.render({
                elem : '#siteFundsTable',
                height : Lib.getTableHeight(1),
                cellMinWidth: 100,
                method : 'post',
                url : Common.ctxPath + '/cms/siteFunds/chushenlist.json' // 数据接口
                ,page : Lib.tablePage // 开启分页
                ,limit : 10,
                cols : [ [ // 表头
                    {
                        type : 'checkbox',
                        fixed:'left',
                    },

                {

                    field : 'unitName', 
                        title : '单位名称',
                    align: 'center',
                    width:"165"
                },
                {

                    field : 'approvalNumber', 
                        title : '批准站文号',
                    align: 'center',
                    width:"200"
                },
                {

                    field : 'name1',
                        title : '工作站名称',
                    align: 'center',
                    width:"165"
                },
                {

                    field : 'fundingProjectsText',
                        title : '资助经费申报项目',
                    align: 'center',
                    width:"165"
                },
                {

                    field : 'declarationAmount', 
                        title : '申报金额',
                    align: 'right',
                    width:"135",templet:function (d) {
                    return Common.getMoney(d.declarationAmount);
                }
                },
                {

                        field : 'businessState',
                        title : '业务状态',
                    align: 'center',
                    width:"90"
                 },
                {

                    field : 'dateReporting',
                        title : '申报日期',
                    align: 'center',
                    width:"165"
                }
        ] ]
        });
            table.on('checkbox(siteFundsTable)', function(obj){
                var siteFunds = obj.data;
                if(obj.checked){
                    //按钮逻辑Lib.buttonEnable()
                }else{

                }
            })
        },
        initSearchForm:function(){
            Lib.initSearchForm( $("#searchForm"),siteFundsTable,form);
        },
        initToolBar:function(){
            toolbar = {
                auditor : function() { // 获取选中数目
                    var data = Common.getOneFromTable(table,"siteFundsTable");
                    if(data==null){
                        return ;
                    }
                    var url = "/cms/siteFunds/shenhe.do?id="+data.id+"&roleName=chushen";
                    Common.openDlg(url,"站点经费资助初审>初审核");
                },
                find : function() { // 获取选中数目
                    var data = Common.getOneFromTable(table,"BusinessProcessTable");
                    if(data==null){
                        return ;
                    }
                    var url = "/cms/siteFunds/findenterprise.do?id="+data.id;
                    Common.openDlg(url,"站点经费>查看");
                },
                process : function() { // 获取选中数目
                    var data = Common.getOneFromTable(table,"BusinessProcessTable");
                    if(data==null){
                        return ;
                    }
                    var url = "/cms/businessProcess/index.do?businessType=10&businessId="+data.id;
                    Common.openDlg(url,"流程信息>编辑");
                },
        };
            $('.ext-toolbar').on('click', function() {
                var type = $(this).data('type');
                toolbar[type] ? toolbar[type].call(this) : '';
            });
        }
    }
    exports('chushenindex',view);

});